home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 8
/
Eagles_Nest_Mac_Collection_Disc_8.TOAST
/
Developer Tools⁄Additions
/
InsideBa1994
/
InsideBasic-94
/
IB 94
/
Dialog Demos
/
Dialog Demo.BAS
next >
Wrap
BASIC Source File
|
1993-02-20
|
5KB
|
198 lines
'___________________________________
'
' Dialog Demo
'
' by Jonathan Durkee
' with Ross W. Lambert
' based on the previous work of
' Chris Stasny
'___________________________________
COMPILE 0,140 '4(DBug) +8(STR#) +128(≠Case)
RESOURCES "Prefs Dialog.Res"
_prefsID = 128
DIM RECORD prefs
DIM pepperoni
DIM blackOlives
DIM mushrooms
DIM canadianBacon
DIM pizzaSize
DIM END RECORD _prefs
DIM gPrefs.prefs
END GLOBALS
'__________________________________________________________________________
' really neato and nifty dialog handling functions
'
LOCAL MODE
LOCAL FN setDTxt(dlog&,which,t$)
DIM itemRect.8
CALL GETDITEM(dlog&,which,type,h&,itemRect)
LONG IF h&
CALL SETITEXT(h&,t$)
CALL SELITEXT(dlog&,which,0,LEN(t$))
END IF
END FN
'
'__________________________________________________________________________
LOCAL MODE
LOCAL FN setDTxt$(dlog&,which)
DIM itemRect.8
t$ = ""
CALL GETDITEM(dlog&,which,type,h&,itemRect)
IF h& THEN CALL GETITEXT(h&,t$)
END FN = t$
'__________________________________________________________________________
LOCAL MODE
LOCAL FN getDBtn(dlog&,which)
DIM itemRect.8
state = 0
CALL GETDITEM(dlog&,which,type,h&,itemRect)
IF h& THEN state = FN GETCTLVALUE(h&)
END FN = state
'__________________________________________________________________________
LOCAL MODE
LOCAL FN setDBtn(dlog&,which,state)
DIM itemRect.8
CALL GETDITEM(dlog&,which,type,h&,itemRect)
IF state THEN state = 1 ' adjust for _ZTrue = -1
LONG IF h& AND FN GETCTLVALUE(h&) <> state
CALL SETCTLVALUE(h&,state)
END IF
END FN
'__________________________________________________________________________
LOCAL FN toggleDBtn(dlog&,which)
state = FN getDBtn(dlog&,which)
FN setDBtn(dlog&,which,state-1)
END FN
'__________________________________________________________________________
LOCAL MODE
LOCAL FN getRect(dlog&,theItem,rPtr&)
DIM t,l,b,r
CALL GETDITEM(dlog&,theItem,itemType,itemH&,t)
BLOCKMOVE @t,rPtr&,8 ' return rectangle to caller
END FN
'__________________________________________________________________________
LOCAL MODE
LOCAL FN frameOKBtn(DLOGPtr&) ' draws a frame around OK btn
DIM penRecord;18 ' a pen record for save/restore pen state
DIM btnRect.8 ' a rect for the dialog rect
CALL GETPENSTATE(penRecord) ' save old pen attributes
PEN 3,3,,8
FN getRect(DLOGPtr&,1,@btnRect)
CALL INSETRECT(btnRect,-4,-4)
CALL FRAMEROUNDRECT(btnRect,16,16)
CALL SETPENSTATE(penRecord) ' restore pen to its old self
END FN
'__________________________________________________________________________
LOCAL FN setGroup(dlog&,b1,b2,setBtn)
FOR btn = b1 TO b2
LONG IF btn = setBtn ' clear all but selected button
FN setDBtn(dlog&,btn,1)
XELSE
FN setDBtn(dlog&,btn,0)
END IF
NEXT
END FN
'__________________________________________________________________________
LOCAL FN getGroup(dlog&,b1,b2)
getBtn = 0
FOR btn = b1 TO b2
IF FN getDBtn(dlog&,btn) THEN getBtn = btn : btn = b2' terminate loop
NEXT
END FN = getBtn
'__________________________________________________________________________
' Item numbers are defined in 'DITL' resource #128.
LOCAL FN getPizzaPrefs
'FN pGcntrRes(_"DLOG",_prefsID) ' for PG:PRO users
DLOGPtr& = FN GETNEWDIALOG(_prefsID,0,-1)
LONG IF DLOGPtr&
CALL GETPORT(oldPort&)
CALL SETPORT(DLOGPtr&) ' must be visible
FN setDBtn(DLOGPtr&,3,gPrefs.pepperoni)
FN setDBtn(DLOGPtr&,4,gPrefs.blackOlives)
FN setDBtn(DLOGPtr&,5,gPrefs.mushrooms)
FN setDBtn(DLOGPtr&,6,gPrefs.canadianBacon)
FN setGroup(DLOGPtr&,7,9,gPrefs.pizzaSize)
FN frameOKBtn(DLOGPtr&)
DO
CALL MODALDIALOG(0,hitItem)
SELECT
CASE (hitItem>2 AND hitItem<7)' topping checkboxes
FN toggleDBtn(DLOGPtr&,hitItem)
CASE (hitItem>6 AND hitItem<10)' size group
FN setGroup(DLOGPtr&,7,9,hitItem)
END SELECT ' OK and Cancel fall through
UNTIL hitItem = 1 OR hitItem = 2' OK or Cancel
LONG IF hitItem = 1 ' only update prefs if OK hit
gPrefs.pepperoni = FN getDBtn(DLOGPtr&,3)
gPrefs.blackOlives = FN getDBtn(DLOGPtr&,4)
gPrefs.mushrooms = FN getDBtn(DLOGPtr&,5)
gPrefs.canadianBacon = FN getDBtn(DLOGPtr&,6)
gPrefs.pizzaSize = FN getGroup(DLOGPtr&,7,9)
END IF
CALL SETPORT(oldPort&)
CALL DISPOSDIALOG(DLOGPtr&)
END IF
END FN
LOCAL FN YN$(bool) ' just for this demo
DIM 3 ans$
LONG IF bool
ans$ = "Yes"
XELSE
ans$ = "No"
END IF
END FN = ans$
' --- Demo Start ----
gPrefs.pizzaSize = 7 ' establish default prefs
gPrefs.pepperoni = _ZTrue
FN getPizzaPrefs
COORDINATE WINDOW
WINDOW 1
PRINT
PRINT "Pizza Prefs Results: "
PRINT
PRINT "Pepperoni: ";FN YN$(gPrefs.pepperoni)
PRINT "Black Olives: " ;FN YN$(gPrefs.blackOlives)
PRINT "Mushrooms: ";FN YN$(gPrefs.mushrooms)
PRINT "Canadian Bacon: ";FN YN$(gPrefs.canadianBacon)
PRINT
SELECT gPrefs.pizzaSize
CASE 7 ' small
pizzaSz$ = "Small"
CASE 8 ' medium
pizzaSz$ = "Medium"
CASE 9 ' large
pizzaSz$ = "Large"
END SELECT
PRINT "pizzaSize: ";pizzaSz$
PRINT
PRINT "Press RETURN to end..."
INPUT r$